
import com.renesys.raceway.views.*;

import java.awt.*;

public class pulsePlayer extends bgpStreamPlayer {
    public static long MIN_DURATION = 100; // ms
    public Color idleColor = new Color(160,176,255);

    private void pulse(Raceway.VisibleHost h) {
	long ms0 = System.currentTimeMillis();
	while (System.currentTimeMillis()-ms0 < MIN_DURATION) {
	    h.scaleSize(1.25);
	    h.scaleSize(0.8);
	}
    }
    public void play(Stream.Record r) {
	String rty = 
	    stream.getRecordTypeString(r.type_code);
	String nhi = 
	    stream.getRecordSourceString(r.source_code);
	if (rty.equals("SSF.OS.BGP4")) {
	    switch((int)r.bytes[r.offset]) {
	    case SSF.OS.BGP4.Monitor.CPU_BUSY:
		Raceway.VisibleHost h = stream.raceway().getVisibleHost(nhi);
		if (null != h) {
		    if (0==r.bytes[r.offset+1]){
			h.setFillColor(idleColor);  // IDLE
		    } else {
			h.setFillColor(Color.red);  // ACTIVE 
			pulse(h);
		    }
		} 
	    default:
				// ignore other records 
		break;
	    }
	}
    }
}
